package com.yixinsoft.basic.service.manage.system;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yixinsoft.basic.mapper.manage.system.OrganizationMapper;
import com.yixinsoft.basic.model.manage.system.Organization;
import com.yixinsoft.basic.service.base.BaseService;

/**
 * Created by hqy on 2016/06/05
 */
@Service
public class OrganizationService extends BaseService<Organization> {
	
	@Autowired
	private OrganizationMapper organizationMapper;
	
	public void move(Organization source, Organization target) {
		organizationMapper.move(target.makeSelfAsParentIds(), source.makeSelfAsParentIds());
		
		source.setParentId(target.getId());
		source.setParentIds(target.getParentIds());
		organizationMapper.updateByPrimaryKeySelective(source);
	}
	
	public List<Organization> findAllWithExclude(Organization organization) {
		return organizationMapper.findAllWithExclude(organization.getId(), organization.makeSelfAsParentIds());
	}
	
	public Integer deleteById(Long organizationId) {
		Organization organization = queryById(organizationId);
		if (organization != null) {
			organizationMapper.deleteByParentIds(organization.makeSelfAsParentIds());
			return super.deleteById(organizationId);
		}
		return 0;
	}
}
